//验证角色的长度，及其是否重复
function checkRoleName(name,nameMsg,type)
{
	var text = $('#' + name).val();
	var boo = false;
	// 验证字符串是否符合规范及其长度范围
	// 将字符串转义
		var re = /^[0-9a-zA-Z\u4e00-\u9fa5]{1,15}$/;

		if (text.search(re) == -1) // 长度超过规定范围count
		{
			$("#" + nameMsg).html(
					"<font color='red'>请输入 汉字、字母、数字,最多15个字符</font>");
			boo = false;
		} else // 长度未超过范围count,则验证重复性
		{

			//验证重复性
      		$.ajax({
				type: "POST",
				url: "../rolemanage/isexistflowrole",
				data: "roleName="+text,
				async:false,
				success : function(data)
				{
					if("1" == data)  //存在
					{
						if (type == 0) {
							$("#"+nameMsg).html("<font color='red'>角色名已存在</font>");
							boo = false;
						} else {
							$("#" + nameMsg).html(
									"&nbsp;&nbsp;<img src='../images/ok.png' />");
							boo = true;
						}
						
					}
					else if("0" == data) //不存在
					{
						$("#"+nameMsg).html("&nbsp;&nbsp;<img src='../images/ok.png' />");
						boo = true;
					}
				} 
			});
		}
	return boo;
}

function checkModel(model,name){
	 var ischeck = $('#'+model+':checked').length;
	if(ischeck == 1)
		{
		$("[name='"+name+"']").attr("checked",'true');
		}
	
	if(ischeck == 0)
		{
		$("[name='"+name+"']").removeAttr("checked");
		}
	var str = "";
	for(var i=1;i<=8;i++)
		{
		$('input[name="authName'+i+'"]:checked').each(function() {
			str += $(this).val() + ",";
		});
		}
	$("#authId").val(str);
}

function checkselect(model,name)
{
	var ischeck = 0;
	$('input[name="'+name+'"]:checked').each(function() {
	   //alert($(this).length);
	   ischeck = $(this).length;
	});
	 //var ischeck = $('#'+name+':checked').length;
	//alert(ischeck);
	if(ischeck == 1)
		{
		$("[name='"+model+"']").attr("checked",'true');
		}
	
	if(ischeck == 0)
		{
		$("[name='"+model+"']").removeAttr("checked");
		}
	var str = "";
	for(var i=1;i<=8;i++)
		{
		$('input[name="authName'+i+'"]:checked').each(function() {
			str += $(this).val() + ",";
		});
		}
	$("#authId").val(str);
}

function delByRoleId(roleId) {
	if (window.confirm('你确定要删除该记录！')) {
		location.href = '../rolemanage/delflowrole?roleId=' + roleId;
	} else {
		return false;
	}
}

function checkselectOrNo()
{
	$("#roleName").val("");
	$("#roleNameMsg").html("必填");
	$("input[type='checkbox']").attr("checked", false);
	
}

function restartCheck()
{
	var text = $('#roleId').val();
	$.ajax({
		type : "post",
		url : "../rolemanage/restartCheck",
		data: "roleId="+text,
		async:false,
		success : function(msg) {
			$("#authHtml").html("");
			$("#authHtml").html(msg);
		}
	});
	}
